(function ($) {
    String.prototype.removeBlankLines = function () {
        return this.replace(/(\n[\s\t]*\r*\n)/g, '\n').replace(/^[\n\r\n\t]*|[\n\r\n\t]*$/g, '')
    }
    var correct_ans  = []
    var correct_ansn = []
    var zmarr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "G", "K"]
    $.fn.paper = function (newAtrr) {
    	correct_ans=[]
    	correct_ansn = []
        var dft = {
            paper: "#paper",
            class: 'm_t'
        };
        var ops = $.extend(dft, newAtrr);
        var list = $(this).val().replace(/ +/g, "").replace(/[0-9]+@/g, "@").split("@");//去除题号，并且从@开始分割
        var tgstr = '';
        for (var i = 1; i < list.length; i++) {
        	console.log(list[i])
            list[i]=list[i].removeBlankLines()
            console.log(list[i])
            var tg = list[i].split("【答案】")[0]//从答案开始分割取第一个
            var da = list[i].split("【答案】")[1]//从答案开始分割取第二个
            if(da.split("。")[0].length>1){
                tgstr += '<ul class="question_list more_list"><li class="question_item">';
            }else{
                tgstr += '<ul class="question_list"><li class="question_item">';
            }
            var tglist = tg.replace(/ +/g, "").replace(/[0-9]+．/g, "@").split("@");
            console.log(tglist)
            var secondlist = '<ul class="answer_list1">'
            var jxstr = '<p class="answer_analysis">【正确答案】'
            var jxStr=getjxSplit(da,i)
            jxstr+=jxStr.jx_text
            correct_ans.push(jxStr.correct)
            correct_ansn.push(changeans(jxStr.correct.toString()))
            $.each(tglist, function (idx, obj) {
                var nowStr = obj
                var nowArr = nowStr.split('A.')
                if (nowArr[0].indexOf('图片') >= 0) {
                    nowArr[0] = nowArr[0].split('图片')[0] + '<img src="./img_tm/tt_' + i + '.png">'
                }
                tgstr += '<p class="question_text">' + i + '、' + nowArr[0] + '</p><ul class="answer_list">'
                var qusarr = ('A.' + nowArr[1]).split('\n')
                console.log(qusarr)
                if(qusarr.length==1){
                    qusarr.length=5
                    for (var k = 0; k < qusarr.length-1; k++) {
                        tgstr += ''
                        secondlist += '<li><span><font></font></span>' + zmarr[k] + '</li>'
                    } 
                }else{
                   for (var k = 0; k < qusarr.length-1; k++) {
                        tgstr += '<li>' + qusarr[k] + '</li>'
                        secondlist += '<li><span><font></font></span>' + zmarr[k] + '</li>'
                    } 
                }
                secondlist += "</ul>"
                tgstr += '</ul>' + secondlist + jxstr
                tgstr += '</li></ul>'
                if(jxStr.dtm_text!=""){
                    tgstr += jxStr.dtm_text
                }
                if(jxStr.xtm_text!=""){
                    tgstr += jxStr.xtm_text
                }
            });
        }
        $('#question_con').html(tgstr)
        $('#paper').text(correct_ans.join('_'))
        $('#paper1').text(correct_ansn.join(','))
        $('#datas').val($("#qus_text").html())
        
    }
    function getjxSplit(str,index){
            var lastStr={}
            lastStr.jx_text=''
            lastStr.dtm_text=''
            lastStr.xtm_text=''
            lastStr.correct=''
            if(str.indexOf('大标题') >=0){
                var str_list=str.split("大标题")
                if(str_list[1].indexOf('小标题') >=0){
                     var tm_list=str_list[1].split('小标题')
                     if (tm_list[0].indexOf('图片') >= 0) {
                        lastStr.dtm_text='<p class="mulv">'+ tm_list[0].split('图片')[0].replace("\n","</br>") + '<img src="./img_tm/tt_' + index+ '.png">' + tm_list[0].split('图片')[1].replace("\n","</br>")+'</p>'
                    }else{
                        lastStr.dtm_text='<p class="mulv">'+ tm_list[0] +'</p>'
                    }
                    if (tm_list[1].indexOf('图片') >= 0) {
                        lastStr.xtm_text='<p class="mulv1">'+ tm_list[1].split('图片')[0].replace("\n","</br>") + '<img src="./img_tm/tt_' + index + 'dd.png">'+ tm_list[1].split('图片')[1].replace("\n","</br>")+'</p>'
                    }else{
                        lastStr.xtm_text='<p class="mulv1">'+ tm_list[1].replace("\n","</br>") +'</p>'
                    }
                }else{
                    if (str_list[1].indexOf('图片') >= 0) {
                        lastStr.dtm_text='<p class="mulv">'+ str_list[1].split('图片')[0].replace("\n","</br>") + '<img src="./img_tm/tt_' + index + '.png">' + str_list[1].split('图片')[1].replace("\n","</br>")+'</p>'
                    }else{
                        lastStr.dtm_text='<p class="mulv">'+ str_list[1].replace("\n","</br>") +'</p>'
                    }
                }
                lastStr.jx_text= getjx(str_list[0],index).text
                lastStr.correct= getjx(str_list[0],index).number
            }else{
                if(str.indexOf('小标题') >=0){
                    var str_list=str.split("小标题")
                    if (str_list[1].indexOf('图片') >= 0) {
                        lastStr.xtm_text='<p class="mulv1">'+ str_list[1].split('图片')[0].replace("\n","</br>") + '<img src="./img_tm/tt_' + (index+1) + '.png">'+ str_list[1].split('图片')[1].replace("\n","</br>")+'</p>'
                    }else{
                        lastStr.xtm_text='<p class="mulv1">'+ str_list[1].replace("\n","</br>") +'</p>'
                    }
                    lastStr.jx_text= getjx(str_list[0],index).text
                    lastStr.correct= getjx(str_list[0],index).number
                }else{
                    lastStr.jx_text= getjx(str,index).text
                    lastStr.correct= getjx(str,index).number
                }
            }
            return lastStr
        }
        function getjx(jxStr,jxIndex){
             var jx_str={}
             jx_str.text=""
             jx_str.number=""
             if(jxStr.indexOf('解析') >=0){
                var strJx = jxStr.split('解析')
                if (strJx[1].indexOf('图片') >= 0) {
                    strJx[1] = strJx[1].split('图片')[0] + '<img src="./img_tm/jx_' + jxIndex + '.png">' +strJx[1].split('图片')[1]
                }
                jx_str.text += strJx[0].split('。')[0] + '<br />【我的答案】<span class="owns_qus"></span><br />【解析】' + strJx[1] + '</p>'
                jx_str.number=strJx[0].split('。')[0]
             }else{
                jx_str.text += jxStr+'<br />【我的答案】<span class="owns_qus"></span>'
                jx_str.number=jxStr[0].split('。')[0]
             }
             return jx_str
        }
        var ansarr=["A","B","C","D","E","F","G","H","I","G","K","L","M","N","P","Q","R","S","T"]
        function changeans(str){
            var laststr=""
            if(str=="0"){
              laststr="未作答"
            }else{
              for(var i=0;i<str.length;i++){
                 laststr+=ansarr.indexOf(str[i])+1
              }
            }
            return laststr
        }
})(jQuery);

